<template>
	<view class="">
		<!-- 自定义头部 -->
		<view class="header_nav">
			<view class="status_bar" :style="{height:recHeight+'px'}"></view><!-- 状态栏 -->
			<view class="header_title" :style="{height:titleBarHeight+'px',top:recHeight+'px',lineHeight:titleBarHeight +'px'}">
				<!-- 顶部导航栏 -->
				<view class="_font-18 _pos-rel _flex-row-mid" style="color: #101010;">
					<navigator open-type="navigateBack" class="_font-18 _pad-x-15 iconfont icon-zuo"></navigator>意见反馈
				</view>
			</view>
			<view class="_w-max img" :style="{height:headerHeight+'px'}"></view>
		</view>
		<view class="_w-max" :style="{height:headerHeight+'px'}"></view>
		<view class="index">
			<form @submit="submitForm">
				<view class="title">意见描述</view>
				<view class="content">
					<textarea v-model="content" name="content" style="height: 86rpx;" placeholder="请输入您的意见内容" placeholder-style="color:#999;"></textarea>
					<view class="img-content">
						<view class="img" v-for="(item,index) in upImage" :key="index" v-if="upImage.length>0">
							<image class="_w-max _h-max" :src="item" mode="scaleToFill"></image>
							<view class="close" @click="delUpImage(index)"></view>
						</view>
						<view class="add_image" @click="uploadImage" v-if="upImage.length < 2">
							<text class="iconfont icon-jiahao2" style="color: #ccc;font-size: 48rpx;"></text>
						</view>
					</view>
				</view>
				<button class="sub-btn theme-color-bg" form-type="submit">提交</button>
			</form>
		</view>
	</view>
</template>

<script>
	import { setUserFeedback } from '@/api/car.js';
	export default {
		data() {
			return {
				recHeight: '', //状态栏高度
				titleBarHeight: '', //顶部标题栏高度
				MenuButtonHeight: '', //小胶囊高度
				MenuButtonTop: '', //顶部距离
				headerHeight: '', //头部总高度
				// shopsListTop: '',
				content: '',
				formdata: {
					content: '',
					thumb: '',
				},
				upImage: [],
			};
		},
		onLoad() {
			uni.hideTabBar();
			this.MenuButtonHeight = uni.getMenuButtonBoundingClientRect().height;
			this.MenuButtonTop = uni.getMenuButtonBoundingClientRect().top;
			this.getPhoneInfo();

		},
		onShow() {

		},
		methods: {
			// 顶部导航栏配置
			getPhoneInfo() {
				let that = this;
				//小程序 配置
				uni.getSystemInfo({
					success(res) {
						that.recHeight = res.statusBarHeight;
						that.titleBarHeight = (that.MenuButtonHeight + (that.MenuButtonTop - res.statusBarHeight) *
							2);
						that.headerHeight = (res.statusBarHeight) + (that.MenuButtonHeight + (that.MenuButtonTop -
							res.statusBarHeight) * 2);
					}
				})
			},
			uploadImage: function() {
				let that = this;
				let opt = {};
				opt.url = 'upload/image';
				that.$util.uploadImageOne(opt, (res) => {
					that.upImage.push(res.data.url);
				});

			},
			delUpImage(index) {
				this.upImage.splice(index, 1);
			},
			submitForm: function(e) {
				let that = this;
				let data = e.detail.value;
				if (that.content == '') {
					return that.$util.Tips({
						title: '请输入反馈'
					});
				}
				uni.showLoading({
					title:'提交中...',
					mask:true
				})
				that.formdata.content = data.content;
				that.formdata.thumb = JSON.stringify(that.upImage);
				setUserFeedback(that.formdata).then((res)=>{
					uni.hideLoading();
					uni.showToast({
						title: "提交成功",
						success() {
							that.content = '';
							that.upImage = [];
						}
					})
				}).catch((err)=>{
					uni.hideLoading();
					uni.showToast({
						title:err,
						icon:'none'
					})
				})
				
			}
		},
	}
</script>

<style scoped lang="scss">
	.header_nav {
		position: fixed;
		top: 0;
		width: 100%;
		z-index: 999;

		//顶部导航栏
		.status_bar {
			width: 100%;
			position: fixed;
			z-index: 9;
			background: linear-gradient(-88.58deg,var(--theme-color-left),var(--theme-color-right));
		}

		.header_title {
			width: 100%;
			position: relative;
			z-index: 999;
			background: linear-gradient(-88.58deg,var(--theme-color-left),var(--theme-color-right));
		}

		.img {
			position: absolute;
			top: 0;
			z-index: 10;
		}

	}

	.index {
		width: 100%;
		background-color: #ffffff;
		padding: 0 40rpx;
		box-sizing: border-box;
		padding-bottom: 56rpx;

		.title {
			box-sizing: border-box;
			padding-top: 66rpx;
			font-weight: 600;
			font-size: 36rpx;
			color: #333333;
		}

		.content {
			width: 100%;
			min-height: 306rpx;
			border-radius: 8rpx;
			background-color: rgba(248, 248, 248, 1);
			margin-top: 22rpx;
			margin-bottom: 60rpx;
			padding: 36rpx;

			.img-content {
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;

				.img {
					flex-shrink: 0;
					width: 150rpx;
					height: 150rpx;
					border-radius: 8rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					// overflow: hidden;
					background-color: #ffffff;
					margin-right: 30rpx;
					margin-bottom: 20rpx;
					position: relative;

					.close {
						width: 34rpx;
						height: 34rpx;
						border-radius: 50%;
						display: flex;
						align-items: center;
						justify-content: center;
						position: absolute;
						z-index: 10;
						top: -18rpx;
						right: -18rpx;
						background-color: #cccccc8c;
						color: #ffffff;

						&::after {
							content: "×";
						}
					}
				}

				.add_image {
					flex-shrink: 0;
					width: 150rpx;
					height: 150rpx;
					border-radius: 8rpx;
					border: 1rpx dashed #999;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}

		.sub-btn {
			width: 100%;
			height: 76rpx;
			line-height: 76rpx;
			border-radius: 200rpx;
			// background: linear-gradient(-88.58deg, rgba(98, 98, 98, 1) -0.63%, rgba(75, 73, 75, 1) 97.9%);
			font-size: 32rpx;
			text-align: center;
			// color: #ffffff;
		}
	}
</style>
